const { list } = require('./mock')
const bodyParser = require('body-parser')

module.exports = app => {
	app.use(bodyParser.json())
	app.post('/api/list', (req, res) => {
		const { isProfect, desc, type } = req.body
		// 复制数据
		let data = [...list];
		// 是否 精选数据
		if (isProfect) {
			data = data.filter(v => v.isProfect)
		}

		// 是否排序
		switch (desc) {
			case '时间':
				data.sort((a, b) => new Date(a.time) - new Date(b.time))
				break
			case '评价':
				data.sort((a, b) => a.mess - b.mess)
				break
			case '收藏':
				data.sort((a, b) => a.collect - b.collect)
				break
		}

		// 筛选
		if (type) {
			data = data.filter(v => v.type === type)
		}


		res.send({
			code: 200,
			data: data
		})

	})
}